package com.sep.team4.data;

import java.util.ArrayList;

import com.google.gson.annotations.SerializedName;

import android.util.Log;

/**
 * Instances of this class represent a course the user attends. It can be used
 * to get information about the course including the tests that belong to it.
 * 
 * @author Mitchell
 * 
 */
public class Course {

	// The name of the course.
	private String name;
	// The semester the course belongs to.
	private String semester;
	// The course code of the course.
	private String code;
	// The amount of SBU the user can obtain in the course.
	private double SBU;
	// An ArrayList containing all the tests that belong to the course.
	private ArrayList<Test> tests;
	// The database id of the course.
	private int courseID;

	/**
	 * The constructor.
	 * 
	 * @param name
	 *            The name of the course.
	 * @param semester
	 *            The semester the course belongs to.
	 * @param code
	 *            The course code of the course.
	 * @param SBU
	 *            The amount of SBU the user can obtain in the course.
	 */
	public Course(String name, String semester, int courseID, String code,
			int SBU) {
		this.name = name;
		this.semester = semester;
		this.code = code;
		this.SBU = SBU;
		this.courseID = courseID;
		tests = null;
	}

	public Course() {
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setSemester(String semester) {
		this.semester = semester;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public void setSBU(double sBU) {
		SBU = sBU;
	}

	public void setTests(ArrayList<Test> tests) {
		this.tests = tests;
	}

	public void setCourseID(int courseID) {
		this.courseID = courseID;
	}

	/**
	 * Returns the name of the course.
	 * 
	 * @return The name of the course.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the semester of the course.
	 * 
	 * @return The semester of the course.
	 */
	public String getSemester() {
		return semester;
	}

	/**
	 * Returns the code of the course.
	 * 
	 * @return The code of the course.
	 */
	public String getCode() {
		return code;
	}

	/**
	 * Returns the EC of the course.
	 * 
	 * @return The EC of the course.
	 */
	public double getSBU() {
		return SBU;
	}

	/**
	 * Returns the courseID of the course.
	 * 
	 * @return The courseIDC of the course.
	 */
	public int getCourseID() {
		return courseID;
	}

	/**
	 * Returns an ArrayList containing all the tests that belong to the course
	 * from the database.
	 * 
	 * @return All the tests that belong to the course.
	 */
	public ArrayList<Test> getTests() {
		if (tests == null) {
			tests = DatabaseManager.getInstance().getTests(courseID);
		}
		return tests;
	}

	/**
	 * Returns the number of ECS the user received for this course.
	 * 
	 * @return The number of ECS the user received for this course.
	 */
	public double getEarnedEC() {
		double weightOfAllTests = 0;
		for (Test test : getTests()) {
			weightOfAllTests += test.getWeightIfEarned();
		}
		return SBU / 28 * (weightOfAllTests / 100);
	}

}
